package com.sthz.facepay.mapper;

import com.sthz.facepay.model.Goods;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

public interface GoodsMapper {
    @Delete({
        "delete from st_goods",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into st_goods (id, name, ",
        "picture, price, number, ",
        "surplus_number, exchange_note, ",
        "exchange_point, start_time, ",
        "end_time, state, ",
        "bcid, specifications, ",
        "disount, remarks, ",
        "go_type, sale_time, ",
        "list_time, list_name, ",
        "purchase_price, suid, ",
        "company)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{picture,jdbcType=VARCHAR}, #{price,jdbcType=DOUBLE}, #{number,jdbcType=INTEGER}, ",
        "#{surplus_number,jdbcType=INTEGER}, #{exchange_note,jdbcType=VARCHAR}, ",
        "#{exchange_point,jdbcType=INTEGER}, #{start_time,jdbcType=TIMESTAMP}, ",
        "#{end_time,jdbcType=TIMESTAMP}, #{state,jdbcType=TINYINT}, ",
        "#{bcid,jdbcType=INTEGER}, #{specifications,jdbcType=VARCHAR}, ",
        "#{disount,jdbcType=VARCHAR}, #{remarks,jdbcType=VARCHAR}, ",
        "#{go_type,jdbcType=VARCHAR}, #{sale_time,jdbcType=TIMESTAMP}, ",
        "#{list_time,jdbcType=TIMESTAMP}, #{list_name,jdbcType=VARCHAR}, ",
        "#{purchase_price,jdbcType=VARCHAR}, #{suid,jdbcType=INTEGER}, ",
        "#{company,jdbcType=VARCHAR})"
    })
    int insert(Goods record);

    @InsertProvider(type=GoodsSqlProvider.class, method="insertSelective")
    int insertSelective(Goods record);

    @Select({
        "select",
        "id, name, picture, price, number, surplus_number, exchange_note, exchange_point, ",
        "start_time, end_time, state, bcid, specifications, disount, remarks, go_type, ",
        "sale_time, list_time, list_name, purchase_price, suid, company",
        "from st_goods",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="picture", property="picture", jdbcType=JdbcType.VARCHAR),
        @Result(column="price", property="price", jdbcType=JdbcType.DOUBLE),
        @Result(column="number", property="number", jdbcType=JdbcType.INTEGER),
        @Result(column="surplus_number", property="surplus_number", jdbcType=JdbcType.INTEGER),
        @Result(column="exchange_note", property="exchange_note", jdbcType=JdbcType.VARCHAR),
        @Result(column="exchange_point", property="exchange_point", jdbcType=JdbcType.INTEGER),
        @Result(column="start_time", property="start_time", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="end_time", property="end_time", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        /*@Result(column="bcid", property="bcid", jdbcType=JdbcType.INTEGER),*/
        @Result(column="specifications", property="specifications", jdbcType=JdbcType.VARCHAR),
        @Result(column="disount", property="disount", jdbcType=JdbcType.VARCHAR),
        @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
        @Result(column="go_type", property="go_type", jdbcType=JdbcType.VARCHAR),
        @Result(column="sale_time", property="sale_time", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="list_time", property="list_time", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="list_name", property="list_name", jdbcType=JdbcType.VARCHAR),
        @Result(column="purchase_price", property="purchase_price", jdbcType=JdbcType.VARCHAR),
        /*@Result(column="suid", property="suid", jdbcType=JdbcType.INTEGER),*/
        @Result(column="company", property="company", jdbcType=JdbcType.VARCHAR),
        @Result(column="suid", property="supplier", one=@One(select="com.sthz.facepay.mapper.SupplierMapper.getById",fetchType = FetchType.EAGER)),
        @Result(column="bcid", property="bigClassification", one=@One(select="com.sthz.facepay.mapper.BigClassificationMapper.getById",fetchType = FetchType.EAGER))
    })
    Goods selectByPrimaryKey(Integer id);

    @UpdateProvider(type=GoodsSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Goods record);

    @Update({
        "update st_goods",
        "set name = #{name,jdbcType=VARCHAR},",
          "picture = #{picture,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=DOUBLE},",
          "number = #{number,jdbcType=INTEGER},",
          "surplus_number = #{surplus_number,jdbcType=INTEGER},",
          "exchange_note = #{exchange_note,jdbcType=VARCHAR},",
          "exchange_point = #{exchange_point,jdbcType=INTEGER},",
          "start_time = #{start_time,jdbcType=TIMESTAMP},",
          "end_time = #{end_time,jdbcType=TIMESTAMP},",
          "state = #{state,jdbcType=TINYINT},",
          "bcid = #{bcid,jdbcType=INTEGER},",
          "specifications = #{specifications,jdbcType=VARCHAR},",
          "disount = #{disount,jdbcType=VARCHAR},",
          "remarks = #{remarks,jdbcType=VARCHAR},",
          "go_type = #{go_type,jdbcType=VARCHAR},",
          "sale_time = #{sale_time,jdbcType=TIMESTAMP},",
          "list_time = #{list_time,jdbcType=TIMESTAMP},",
          "list_name = #{list_name,jdbcType=VARCHAR},",
          "purchase_price = #{purchase_price,jdbcType=VARCHAR},",
          "suid = #{suid,jdbcType=INTEGER},",
          "company = #{company,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Goods record);
}